<template>
  <div class="playBox">
    <div class="listTop">
      <div
        class="blur"
        :style="{ backgroundImage: `url(${$root.musicStore.picUrl})` }"
      ></div>
      <img v-lazy="$root.musicStore.picUrl" />
      <div class="text">
        <span>{{ $root.musicStore.text }}</span>
      </div>
      <router-link to="/" @click="clearList">
        <van-icon
          name="revoke"
          style="text-shadow: 0 0 0.2em rgb(244, 247, 81)"
          color="white"
          size="30"
      /></router-link>
    </div>
    <Loading v-if="songDetail.length == 0"></Loading>

    <ul class="newsong" v-if="songDetail.length > 0">
      <p>歌单列表</p>
      <li class="li" v-for="(s, index) in songDetail" :key="s.id">
        <span class="one">{{ index + 1 }}</span>
        <SongItem :item="s"></SongItem>
      </li>
      <p>精彩评论</p>

      <li class="li" v-for="(s, index) in hotComments" :key="index">
        <HotComments :item="s" v-if="hotComments.length > 0"></HotComments>
      </li>
      <template v-if="hotComments.length <= 0">
        <p class="textComments">暂无评论...</p></template
      >
    </ul>
    <div
      :style="{ paddingBottom: $root.musicStore.musicID ? '50px' : '0' }"
    ></div>
  </div>
</template>

<script>
import SongItem from "@/components/SongItem";
import Loading from "@/components/myLoading";
import HotComments from "@/components/HotComments";
export default {
  name: "PlayList",
  components: {
    SongItem,
    Loading,
    HotComments
  },
  data() {
    return {
      listID: null,
      songList: [],
      str: "",
      songDetail: [],
      hotComments: []
    };
  },
  methods: {
    clearList() {
      this.songDetail = [];
      this.hotComments = [];
      this.songList = [];
    }
  },
  created() {
    this.listID = this.$route.params.id;
    // console.log(this.$route);
    this.$root.musicStore.picUrl = this.$route.query.url;
    this.$root.musicStore.text = this.$route.query.name;

    this.$axios
      .get("/playlist/detail?id=" + this.listID)
      .then(data => {
        this.songList = data.data.playlist.trackIds;

        this.songList.forEach((item, index) => {
          if (index == this.songList.length - 1) {
            this.str += item.id;
          } else {
            this.str += item.id + ",";
          }
        });
        return this.str;
      })
      .then(str => {
        this.$axios
          // .get("http://music.kele8.cn/song/detail?ids=" + str)
          .get("/song/detail?ids=" + str)
          .then(data => {
            this.songDetail = data.data.songs;
          });
      });

    this.$axios.get("/comment/playlist?id=" + this.listID).then(data => {
      this.hotComments = data.data.hotComments;
    });
  }
};
</script>

<style lang="less" scoped>
.newsong {
  p {
    font-size: 13px;
    margin: 20px 0 10px;
    padding-left: 10px;
    // background-color: rgb(238, 239, 240);
  }
  .textComments {
    // background-color: rgba(244, 247, 81, 0.9);
    text-align: center;
    font-size: 16px;
  }
}

.listTop {
  position: relative;
  width: 100vw;
  height: 300px;
  display: flex;
  padding: 0 20px;
  // background-color: rgba(0, 0, 0, 0.25);
  background-size: 100%;
  justify-content: flex-start;
  align-items: center;
  .blur {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    filter: blur(5px);
    background-size: 100%;
  }
  img {
    width: 145px;
    height: 145px;
    z-index: 1;
  }
  .text {
    flex: 1;
    height: 145px;
    padding: 0 20px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;

    text-shadow: 0 0 0.2em rgba(244, 247, 81, 0.9);
  }
  a {
    position: absolute;
    top: 5px;
    right: 10px;
    z-index: 1;
  }
}
.li {
  display: flex;
  &:first-of-type {
    span {
      color: yellow;
    }
  }
  &:nth-of-type(2) {
    span {
      color: #c0c0c0;
    }
  }
  &:nth-of-type(3) {
    span {
      color: rgb(233, 183, 124);
    }
  }
  span {
    display: inline-block;
    line-height: 50px;
    margin: 0 8px;
    color: rgb(240, 240, 240);
  }

  div {
    flex: 1;
  }
}
</style>
